package com.htl.exampro.paper.controller;

import com.htl.exampro.base.model.PageResult;
import com.htl.exampro.base.model.ServerResponse;
import com.htl.exampro.paper.pojo.query.PaperPageParam;
import com.htl.exampro.paper.pojo.vo.PaperVO;
import com.htl.exampro.paper.service.PaperService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 试卷表 前端控制器
 * </p>
 *
 * @author hehehe
 * @since 2025-05-26
 */
@Tag(name = "试卷管理", description = "试卷相关接口")
@RestController
@RequestMapping("/paper")
public class PaperController {

    @Autowired
    private PaperService paperService;

    @Operation(summary = "查询试卷", description = "根据主键查询试卷信息")
    @GetMapping("/{id}")
    public ServerResponse<PaperVO> queryPaperById(@PathVariable("id") String id) {
        PaperVO paperVO = paperService.queryPaperById(id);
        return ServerResponse.success(paperVO);
    }

    @Operation(summary = "分页查询试卷", description = "支持按条件分页查询试卷列表")
    @PostMapping("/page")
    public ServerResponse<PageResult<PaperVO>> queryPaperPage(@Validated @RequestBody PaperPageParam pageParam) {
        PageResult<PaperVO> pageResult = paperService.queryPaperPage(pageParam);
        return ServerResponse.success(pageResult);
    }

    @Operation(summary = "保存试卷", description = "保存试卷")
    @PostMapping("")
    public ServerResponse<Integer> savePaper(@Validated @RequestBody PaperVO paperVO) {
        int i = paperService.savePaper(paperVO);
        return ServerResponse.success(i);
    }

    @Operation(summary = "修改试卷", description = "修改试卷")
    @PutMapping("")
    public ServerResponse<Integer> updatePaper(@Validated @RequestBody PaperVO paperVO) {
        int i = paperService.updatePaper(paperVO);
        return ServerResponse.success(i);
    }

    @Operation(summary = "删除试卷", description = "根据主键删除试卷信息")
    @DeleteMapping("/{id}")
    public ServerResponse<Boolean> delPaperById(@PathVariable("id") String id) {
        return ServerResponse.success(paperService.removeById(id));
    }
}
